package com.pyg.goods.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import com.pyg.pojo.TbContentCategoryExample;
import com.pyg.pojo.TbContentCategoryExample.Criteria;
import com.pyg.mapper.TbContentCategoryMapper;
import com.pyg.pojo.TbContentCategory;
import com.pyg.goods.service.TbContentCategoryService;

import com.pyg.utils.PygStringUtils;
import entity.PageResult;

/**	*  @Author zhuliangcai
*  @Email zhuliangcai@itcast.cn
*  @Date 2018-04-03 20:07:45
*/
@Service
public class TbContentCategoryServiceImpl implements TbContentCategoryService {
	@Autowired
	private TbContentCategoryMapper tbContentCategoryMapper;

	@Override
	public List<TbContentCategory> findAll() {
		return tbContentCategoryMapper.selectByExample(null);
	}

	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		// 开启分页插件功能
		PageHelper.startPage(pageNum, pageSize);

		Page<TbContentCategory> page = (Page<TbContentCategory>) tbContentCategoryMapper.selectByExample(null);

		return new PageResult(page.getTotal(), page.getResult());
	}

	/**
	 * 品牌条件分页
	 *
	 * @param TbContentCategory
	 *            查询条件
	 * @param pageNum
	 *            当前页面
	 * @param pageSize
	 *            每页记录数
	 * @return
	 */
	@Override
	public PageResult findPage(TbContentCategory tbContentCategory, int pageNum, int pageSize) {
		// 开启分页插件功能
		PageHelper.startPage(pageNum, pageSize);

		TbContentCategoryExample example = null;
		if (tbContentCategory != null) {
			example = new TbContentCategoryExample();
			Criteria criteria = example.createCriteria();
			if (PygStringUtils.isNotEmpty(tbContentCategory.getName())) {
				criteria.andNameLike("%" + tbContentCategory.getName() + "%");
			}
		}

		Page<TbContentCategory> page = (Page<TbContentCategory>) tbContentCategoryMapper.selectByExample(example);

		return new PageResult(page.getTotal(), page.getResult());
	}

	@Override
	public void add(TbContentCategory tbContentCategory) {
		tbContentCategoryMapper.insert(tbContentCategory);
	}

	@Override
	public void del(Long[] ids) {
		for (Long id : ids) {
			tbContentCategoryMapper.deleteByPrimaryKey(id);
		}
	}

	@Override
	public TbContentCategory findOne(Long id) {
		return tbContentCategoryMapper.selectByPrimaryKey(id);
	}

	@Override
	public void update(TbContentCategory tbContentCategory) {
		tbContentCategoryMapper.updateByPrimaryKey(tbContentCategory);
	}

}
